﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PlugMeterControl
{
    public partial class CalibrationForm : Form
    {
        private FormMain m_parent;
        private int calibrationState = 0;

        public CalibrationForm(FormMain frm)
        {
            InitializeComponent();
            m_parent = frm;
        }

        public void SetCalibrationState(int state)
        {
            calibrationState = state;
            ButtonPrevious.Enabled = false;
            ButtonNext.Enabled = false;
            ButtonStore.Enabled = false;
            switch (calibrationState)
            {
                case 1:
                    TextBoxCalibration.Text = "calibrating VOLTAGE input";
                    break;
                case 2:
                    TextBoxCalibration.Text = "FINISHED calibrating VOLTAGE input";
                    System.Threading.Thread.Sleep(500);
                    TextBoxCalibration.Text = "Connect Load for calibrating I_HIGHGAIN input";
                    ButtonPrevious.Enabled = true;
                    ButtonNext.Enabled = true;
                    break;
                case 3:
                    TextBoxCalibration.Text = "calibrating I_HIGHGAIN input";
                    break;
                case 4:
                    TextBoxCalibration.Text = "FINISHED calibrating I_HIGHGAIN input";
                    System.Threading.Thread.Sleep(500);
                    TextBoxCalibration.Text = "calibrating phase correction I_HIGHGAIN input";
                    break;
                case 5:
                    TextBoxCalibration.Text = "FINISHED calibrating phase correction I_HIGHGAIN input";
                    System.Threading.Thread.Sleep(500);
                    TextBoxCalibration.Text = "Connect Load for calibrating I_LOWGAIN input";
                    ButtonPrevious.Enabled = true;
                    ButtonNext.Enabled = true;
                    break;
                case 6:
                    TextBoxCalibration.Text = "calibrating I_LOWGAIN input";
                    break;
                case 7:
                    TextBoxCalibration.Text = "FINISHED calibrating I_LOWGAIN input";
                    System.Threading.Thread.Sleep(500);
                    TextBoxCalibration.Text = "calibrating phase correction I_LOWGAIN input";
                    break;
                case 8:
                    TextBoxCalibration.Text = "FINISHED calibrating phase correction I_LOWGAIN input";
                    System.Threading.Thread.Sleep(500);
                    TextBoxCalibration.Text = "Press STORE to programm calibartion setting into the Plugmeter";
                    ButtonPrevious.Enabled = true;
                    ButtonNext.Enabled = true;
                    ButtonStore.Enabled = true;
                    break;
            }
        }

        private void ButtonCancel_Click(object sender, EventArgs e)
        {
 //           m_parent.CalibrationCancel();
            calibrationState = 0;
            Hide();
        }

        private void ButtonPrevious_Click(object sender, EventArgs e)
        {
            if (calibrationState != 0)
            {
      //          m_parent.CalibrationPrevious();
                ButtonPrevious.Enabled = false;
                ButtonNext.Enabled = false;
            }
        }

        private void ButtonNext_Click(object sender, EventArgs e)
        {
            if (calibrationState != 0)
            {
        //        m_parent.CalibrationNext();
                ButtonPrevious.Enabled = false;
                ButtonNext.Enabled = false;
            }
        }

        private void ButtonStore_Click(object sender, EventArgs e)
        {
            if (calibrationState != 0)
            {
      //          m_parent.CalibrationStore();
            }
            Hide();
        }
    }
}
